package com.example.administrator.u17.fragment;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.example.administrator.u17.R;
import com.example.administrator.u17.adapter.BookViewPageAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/11/14.
 */

public class BookFraqment extends Fragment{
    private TabLayout tabLayout;
    private ViewPager vp;
    private ImageView ivDelete;
    private String[] titles={"收藏","历史","下载"};
    private List<Fragment> list;
    private BookViewPageAdapter adapter;
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=View.inflate(getActivity(), R.layout.frangment_book,null);
        initView(view);
        initData();
        setData();
        return view;
    }

    private void setData() {
        vp.setAdapter(adapter);
        tabLayout.setupWithViewPager(vp);
        tabLayout.setTabTextColors(Color.GRAY,Color.rgb(140,224,88));
        tabLayout.setSelectedTabIndicatorHeight(5);
        tabLayout.setSelectedTabIndicatorColor(Color.rgb(140,224,88));
    }

    private void initData() {
        list=new ArrayList<>();
        list.add(new ShouCangFragment());
        list.add(new LiShiFragment());
        list.add(new DownLoadFragment());
        adapter=new BookViewPageAdapter(getActivity().getSupportFragmentManager(),list,titles);
    }

    private void initView(View view) {
        tabLayout=(TabLayout)view.findViewById(R.id.tablayout_fragment_book);
        vp=(ViewPager)view.findViewById(R.id.vp_fragment_book);
        ivDelete=(ImageView)view.findViewById(R.id.iv_fragment_book_back);
    }
}
